<template>
    <div class="account-detail">
        <iframe  style="height:100vh;" ref="billIframe" :src="ifarmeSrc" frameborder="0" width="100%" scrolling="no" id="billIframe" ></iframe>
    </div>
</template>

<script>
import {findByEpId} from '@/api/stock'
export default {
    data(){
        return{
            ifarmeSrc:'',
            companyList:[],
        }
    },
    created(){
        this.ifarmeSrc = process.env.VUE_APP_BASE_URL_WINNER_URL + 'finance/account';
        // console.log(this.ifarmeSrc,'33333333');
    },
    methods:{
        async handercompany(){
            let date = await findByEpId();
            if( date.success){
                this.companyList = date.result;
                let oIframeDom = document.getElementById('billIframe');
                // 父页面向子页面传参
                let data = {
                    type: 'supplier',
                    code:200,
                    companyList:this.companyList,
                };
                console.log(data,'image.pngimage.png');
                oIframeDom.onload = () => {
                    console.log("parent onload");
                    document.getElementById("billIframe").contentWindow.postMessage(data, '*');
                };
            }else{
                this.$message.error(date.message)
            }
        },
        handleBillMessage(event){
            const {data} = event
            console.log(data,'---------------bill');
            if(data.type === 'billChild'){
                console.log(data.data,'子传父数据');
                // let orderObj = JSON.stringify(data.data);
                this.$router.push({name:'billDetail'})
                // sessionStorage.setItem('bill',orderObj);
            }    
        },
        initIframe(){
            // let oIframeDom = document.getElementById('billIframe');
            // const deviceHeight = document.documentElement.clientHeight;
            // oIframeDom.style.height = (Number(deviceHeight)-120) + 'px'; //数字是页面布局高度差
        },
       
    },
    mounted(){
        this.handercompany();
         // 接收子页面传来的数据
        window.addEventListener('message',this.handleBillMessage);
        this.initIframe();
        let that = this;
        window.onresize = function(){
            that.initIframe();
        }  
    },
    destroyed(){
        window.removeEventListener('message',this.handleBillMessage);
    },
    
}
</script>
<style scoped>
    .account-detail{
        width: 100%;
        height: 100vh;
    }
</style>